<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style media="screen">
    *{
      margin: 0;
      padding: 0;
    }
    li{
      list-style: none;
      line-height: 50px;
      text-indent: 24px;
      width: 300px;
    }
    li.title{
      background-color: #232830;
      color: #63808B;
    }
    ul.innerUl{
      height: 0px;
      overflow: hidden;
      transition: .5s;
    }
    ul.innerUl li{
      background-color: #233847;
      color: #63808B;
    }
  </style>
</head>
<body>
  <ul>
    <li class="title">I am a teacher</li>
    <li>
      <ul class="innerUl">
        <li>I am a teacher1</li>
        <li>I am a teacher1</li>
        <li>I am a teacher1</li>
        <li>I am a teacher1</li>
      </ul>
    </li>
    <li class="title">I am a teacher</li>
    <li>
      <ul class="innerUl">
        <li>I am a teacher2</li>
        <li>I am a teacher2</li>
        <li>I am a teacher2</li>
        <li>I am a teacher2</li>
      </ul>
    </li>
  </ul>
  <script type="text/javascript">
    allLiTitle = document.getElementsByClassName('title');
    for (var i = 0; i < allLiTitle.length; i++) {
      allLiTitle[i].onclick = function(){
        var nextLi = this.nextElementSibling.getElementsByClassName('innerUl')[0];
        if (nextLi.style.height) {
          nextLi.style.height = '';
        }else{
          var allInnerLi = nextLi.getElementsByTagName('li');
          var everyLiHeight = 50;
          var allLiHeight = everyLiHeight * allInnerLi.length + 'px';
          nextLi.style.cssText = 'height:' + allLiHeight + ';';
        }
      }
    }
  </script>
</body>
</html>
